package com.a3dweijing.wetouch2.Activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.base.BaseActivity;
import com.a3dweijing.wetouch2.bean.ReportInfoMSg;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by yxd on 2017/12/2.
 */

public class ReportWebViewActivity extends BaseActivity {
    @BindView(R.id.webiew_web)
    WebView webiewWeb;
    @BindView(R.id.progressBar)
    ProgressBar progressBar;
    @BindView(R.id.webiew_louding)
    LinearLayout webiewLouding;
    String url="";
    ReportInfoMSg.ListBean bean;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_report);
        ButterKnife.bind(this);
        bean= (ReportInfoMSg.ListBean) getIntent().getSerializableExtra("bean");
        if (bean!=null)
        {
            url="http://47.104.196.168/uploads/"+bean.getUser_tel()+"/"+bean.getUser_tel()+"+"+bean.getCreate_time()+"/"+bean.getAnga_report_name();
            Log.e("--", "onCreate: "+url);
        }
        initView();
        initData();
    }
    private void initView() {
        webiewLouding.setVisibility(View.VISIBLE);
//        支持javaScript
        webiewWeb.getSettings().setJavaScriptEnabled(true);
//        是否支持viewport
        webiewWeb.getSettings().setUseWideViewPort(true);
//        是否适配webiewWeb的宽度
        webiewWeb.getSettings().setLoadWithOverviewMode(true);
        webiewWeb.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
//        设置支持的字符集
        webiewWeb.getSettings().setDefaultTextEncodingName("UTF-8");
        webiewWeb.getSettings().setDomStorageEnabled(true);
//        webiewWeb.setInitialScale(150);
        webiewWeb.setScaleX((float) 1.5);
        webiewWeb.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
//设置WebChromeClient类
        webiewWeb.setWebChromeClient(new WebChromeClient() {
            //获取网站标题
            @Override
            public void onReceivedTitle(WebView view, String title) {

            }

            //获取加载进度
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress < 100) {
                    String progress = newProgress + "%";
                    Log.e("--", progress);
                } else if (newProgress == 100) {
                    String progress = newProgress + "%";
                    Log.e("--", progress);
                }
            }
        });


        //设置WebViewClient类
        webiewWeb.setWebViewClient(new WebViewClient() {
            //设置加载前的函数
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                Log.e("--", "开始加载了");

            }

            //设置结束加载函数
            @Override
            public void onPageFinished(WebView view, String url) {
                Log.e("--", "结束加载了");
                webiewLouding.setVisibility(View.GONE);

            }
        });

    }
    private void initData(){
        if (url!=null && url.length()>0){
            webiewWeb.loadUrl(url);
        }
    }



}
